// import { defaultRoomName } from "../util/constants";

import { errLog } from "../util/log";

/**
 * 
 * @param {String[]} names 
 * @returns {String[]}
 */
export function getCreepNames(names){
    if(!names){
        return [];
    }
    try{
        return names.filter((name)=>Boolean(Game.creeps[name]));
    }catch(e){
        errLog(e);
        return [];
    }
}

export class GroupInfo{
    constructor(){
        this.size = 0;
        this.totalResource = {};
        this.totalCost = 0;
    }

    /**
     * 
     * @param {GroupInfo} info 
     */
    add(info){
        this.size+=info.size;
        for(const type in info.totalResource){
            this.totalResource[type] = info.totalResource[type];
        }
    }
}

export class Group{
    /**
     * 
     * @param {Room} spawnRoom 
     */
    constructor(spawnRoom=undefined){
        this.spawnRoom=spawnRoom;
    }
    get spawnRoom(){
        if(this.spawnRoomName===undefined){
            return undefined;
        }
        return Game.rooms[this.spawnRoomName];
    }
    /**
     * 
     * @param {Room} spawnRoom 
     */
    set spawnRoom(spawnRoom){
        if(spawnRoom!==undefined){
            this.spawnRoomName=spawnRoom.name;
        }
    }

    get self(){
        return this;
    }
    get info(){
        return new GroupInfo();
    }

    getClassName(){
        return this.constructor.name;
    }
    serialize(){
        return {spawnRoomName: this.spawnRoomName};
    }
    deserialize(obj){
        if(obj.spawnRoomName!=undefined){
            this.spawnRoomName=obj.spawnRoomName;
        }
        return this;
    }

    run(){
        return ERR_INVALID_ARGS;
    }
    spawn(){
        return ERR_INVALID_ARGS;
    }
    toString(){
        let ans=this.getClassName()+' '+JSON.stringify(this);
        return ans;
    }
}